package com.jsp.user.dao;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.vo.Balance;
import com.vo.Logrecord;
import com.vo.Payment;
import com.vo.Person;
import com.vo.Rate;

public class UserDao {
	public List<Logrecord> getLogrecords(int id) {
		return Logrecord.dao.find("SELECT * FROM logrecord l where l.id=" + id
				+ " ORDER BY l.exittime DESC");
	}

	public List<Balance> getBalance(int id) {
		return Balance.dao.find("select * from balance b where b.id = " + id);
	}

	public List<Rate> getRate(int id) {
		return Rate.dao.find("select * from rate r where r.id = " + id);
	}

	public List<Payment> getPaymList(int id) {
		return Payment.dao.find("select p.id, p.key from payment p where p.id="
				+ id);
	}

	public boolean getPaymentboo(int id, String payment) {
		boolean boo = false;
		List<Payment> payList = Payment.dao
				.find("select * from payment p where p.id=" + id
						+ " and p.payment='" + payment + "'");
		if (payList.size() > 0) {
			boo = true;
		}
		return boo;
	}

	public boolean getPasswordboo(int id, String password) {
		boolean boo = false;
		List<Person> personList = Person.dao
				.find("select p.email from person p where p.id=" + id
						+ " and p.password='" + password + "'");
		if (personList.size() > 0) {
			boo = true;
		}
		return boo;
	}

	public Long getOrdersCount() {
		SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String startime = ft.format(date);
		String endtime = ft.format(date.getTime() + 24 * 60 * 60 * 1000);
		Long cou = Db
				.queryLong("SELECT COUNT(*) from orders o where o.r1_Code = 1 and o.CreateTime BETWEEN '"
						+ startime + "' and '" + endtime + "'");
		return cou;
	}

	public Long getCardOrdersCount() {
		SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String startime = ft.format(date);
		String endtime = ft.format(date.getTime() + 24 * 60 * 60 * 1000);
		Long cou = Db
				.queryLong("SELECT COUNT(*) from cardorder o where o.r1_Code = 1 and o.CreateTime BETWEEN '"
						+ startime + "' and '" + endtime + "'");
		return cou;
	}

	public Long getCirclipCount() {
		SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String startime = ft.format(date);
		String endtime = ft.format(date.getTime() + 24 * 60 * 60 * 1000);
		Long cou = Db
				.queryLong("SELECT COUNT(*) from circlip c where c.result=2000 and c.datetime BETWEEN '"
						+ startime + "' and '" + endtime + "'");
		return cou;
	}

	public Long getRechargeCount() {
		SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String startime = ft.format(date);
		String endtime = ft.format(date.getTime() + 24 * 60 * 60 * 1000);
		Long cou = Db
				.queryLong("SELECT COUNT(*) FROM recharge r where r.r1_Code=1 and r.CreateTime BETWEEN '"
						+ startime + "' and '" + endtime + "'");
		return cou;
	}
}
